// import Vue from 'vue';
import { createRouter, createWebHistory, createWebHashHistory, RouterOptions, RouteRecordRaw } from 'vue-router';

// Vue.use(VueRouter);

// const routerPush = VueRouter.prototype.push;
// VueRouter.prototype.push = function push(location) {
// 	return routerPush.call(this, location).catch(error=> error)
// }
// 组件异步加载器
const loadPage = function(page:any) {
	const tmpArr = page.split('/'),
        path = tmpArr.slice(0, -1).join('/'),
        com = tmpArr[tmpArr.length - 1];
    return () => import(`@/pages${path}/${com}.vue`);
};
/* 导入异步组件 */
const Index = loadPage('Index');
const Login = loadPage('Login');
const Register = loadPage('Register');

/* 创建路由 */
const routes = [
	{
		path: '/',
		name: 'Index',
		component: Index,
		children: [{path: '/', name: 'home', component: loadPage('Home'),meta: {id: 0,index: 0, title: '首页',icon: 'el-icon-s-home', type: 1, show: 1}}],
	},
	{path: '/login', component: Login},
	{path: '/register', component: Register}
];

const router = createRouter({
	// mode: 'history',
	history: createWebHashHistory(),
	routes
});

export default router